package cn.kgc.dao.impl;

import cn.kgc.dao.SmbmsUserDao;
import cn.kgc.entity.SmbmsUser;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * @author Rock
 * @create 2020-08-24 21:44
 */
@Repository("SmbmsUserDao")
public class SmbmsUserDaoImpl implements SmbmsUserDao {

    @Autowired
    private QueryRunner queryRunner;


    public List<SmbmsUser> queryAll() throws SQLException {
        String sql = "select * from smbms_user";
        return queryRunner.query(sql,new BeanListHandler<SmbmsUser>(SmbmsUser.class));
    }

    public List<SmbmsUser> queryUserByName(String userName) throws SQLException {
        String sql = "select * from smbms_user where userName like ?";
        String newStr = "%"+userName+"%";
        return queryRunner.query(sql,new BeanListHandler<SmbmsUser>(SmbmsUser.class),newStr);
    }
}
